 #ifdef __WXMSW__

  #include <stdio.h>
  #include <process.h>

  typedef SOCKADDR_IN sockaddr_in;

  #define   end_socket( s ) { \
             shutdown( s, 0x02 ); \
             closesocket( s ); \
             s = 0; \
            }
 #else

  #include <stdio.h>
  #include <stdlib.h>
  #include <ctype.h>
  #include <unistd.h>
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <netdb.h>
  #include <sys/time.h>
  #include <string.h>
  #include <pthread.h>
  #include <errno.h>
  #include <signal.h>
  #include <fcntl.h>

  #define   end_socket ( s )   ( shutdown( s, 0x02 ) , close( s ) )
  typedef   int                  SOCKET;

#endif

 /* OpenSSL headers */

 #include <openssl/bio.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 #include <assert.h>

 #define FLAG_SECURE       0x01
 #define STATE_NEW         0x20

 typedef struct _sec
 {
   unsigned char  flags;   
   SSL           *ssl;
 }SEC;

 #define STATE_NEW         0x20
 #define STATE_DC          0x21
 #define PROTO_FTP_CC      0x01
 #define PROTO_FTP_DC      0x02 /* LIST */
 #define PROTO_FTP_RETR    0x03 /* RETR */
 #define PROTO_FTP_STOR    0x04 /* STOR */
 #define PROTO_XMPP        0x05

 #define MAX_SESSIONS       5
 
 class connection
 {
   public:
    char         m_host[256];
    char         m_port[8];
    char         m_protocol;
    void       * m_user;
    void       * m_password;
    void       * j_jid;
    void       * j_ss;
    void       * j_vcard;
    long         j_nMail;
    SOCKET       m_sd;
    char         m_state;
    SEC          m_sec;
    bool         isPrimary;

    connection() { memset(this, 0, sizeof (connection)); }
    ~connection() { memset(this, 0, sizeof (connection)); }

    int send_data(char *, int);
    int recv_data(char *, int, int);
 };

 int 
  socket_connect(char *, char *, SOCKET *, bool);

 void
  queue_connection(connection *);

 #define MAX_RBUF 16384